Component({
  properties: {
    // 这里定义了innerText属性，属性值可以在组件使用时指定
    innerText: {
      type: String,
      value: 'default value',
    }
  },
  data: {
    // 这里是一些组件内部数据
    form: {
      morphineInjection: '',
      morphineTablets: '',
      morphineSulfate: '',
      MinOxycodoneHydrochloride: '',
      MaxOxycodoneHydrochloride: '',
      Minhydromorphone: '',
      Maxhydromorphone: '',
      OxycodoneHydrochloride: '',
      fentanyl: '',
      breakthroughPain: '',
      morphineBolt: '',
      sufentanil: ''
    }
  },
  methods: {
    // 吗啡针剂计算
    morphineInjection(e) {
      let value = e.detail.value
      let form = {
        morphineInjection: value,
        sufentanil: this.calculate(value),
        morphineTablets: this.calculate(value * 3),
        morphineSulfate: this.calculate(value * 3),
        MinOxycodoneHydrochloride: this.calculate(value * 1.5),
        MaxOxycodoneHydrochloride: this.calculate(value * 2),
        hydromorphone:  this.calculate(value/5),
        Minhydromorphone: this.calculate(value/8),
        Maxhydromorphone: this.calculate(value/5),
        fentanyl: this.calculate(value * 0.21),
      }

      this.setData({
        form: form
      })
    },

    //吗啡片剂
    morphineTablets(e) {
      let value = e.detail.value
      let form = {
        morphineInjection: this.calculate(value / 3),
        sufentanil: this.calculate(value/3),
        morphineTablets: value,
        morphineSulfate: value,
        hydromorphone: this.calculate(value/5/3),
        Minhydromorphone: this.calculate(value/8/3),
        Maxhydromorphone: this.calculate(value/5/3),
        MinOxycodoneHydrochloride: this.calculate(value * 0.5),
        MaxOxycodoneHydrochloride: this.calculate(20 / 30 * value),
        fentanyl: this.calculate(this.calculate(2.1 / 30 * value)),
        // breakthroughPain: `${this.calculate(value * 0.1)} ~ ${this.calculate(value * 0.2)}`,
      }

      this.setData({
        form: form
      })
    },

    //硫酸吗啡缓释片
    morphineSulfate(e) {
      let value = e.detail.value
      let form = {
        morphineInjection: this.calculate(value / 3),
        sufentanil: this.calculate(value / 3),
        morphineTablets: value,
        morphineSulfate: value,
        hydromorphone: this.calculate(value/5/3),
        Minhydromorphone: this.calculate(value/8/3),
        Maxhydromorphone: this.calculate(value/5/3),
        MinOxycodoneHydrochloride: this.calculate(value * 0.5),
        MaxOxycodoneHydrochloride: this.calculate(20 / 30 * value),
        fentanyl: this.calculate(this.calculate(2.1 / 30 * value)),
        // breakthroughPain: `${this.calculate(value * 0.1)} ~ ${this.calculate(value * 0.2)}`
      }

      this.setData({
        form: form
      })
    },

    // 舒芬太尼注射液
    sufentanil(e) {
      let value = e.detail.value
      let form = {
        sufentanil: value,
        morphineInjection: this.calculate(value),
        morphineTablets: this.calculate(value * 3),
        morphineSulfate: this.calculate(value * 3),
        hydromorphone: this.calculate(value/5),
        Minhydromorphone: this.calculate(value/8),
        Maxhydromorphone: this.calculate(value/5),
        MinOxycodoneHydrochloride: this.calculate(value * 1.5),
        MaxOxycodoneHydrochloride: this.calculate(value * 2),
        fentanyl: this.calculate(value * 0.21),
        // breakthroughPain: `${this.calculate(value * 0.3)} ~ ${this.calculate(value * 0.6)}`,
      }

      this.setData({
        form: form
      })
    },

    //最小值盐酸羟考酮缓释片
    MinOxycodoneHydrochloride(e) {
      let value = e.detail.value
      let form = {
        morphineInjection: this.calculate(10 / 15 * value),
        sufentanil: this.calculate(10 / 15 * value),
        morphineTablets: this.calculate(30 / 15 * value),
        morphineSulfate: this.calculate(30 / 15 * value),
        hydromorphone:  this.calculate(10 / 15 / 5 * value),
        Minhydromorphone:  this.calculate(10 / 15 / 8 * value),
        Maxhydromorphone:  this.calculate(10 / 15 / 5 * value),
        MinOxycodoneHydrochloride: value,
        MaxOxycodoneHydrochloride: this.calculate(20 / 15 * value),
        fentanyl: this.calculate(2.1 / 15 * value),
        // breakthroughPain: `${this.calculate(3 / 15 * value)} ~ ${this.calculate(6 / 15 * value)}`
      }

      this.setData({
        form: form
      })
    },

    //最大值盐酸羟考酮缓释片
    MaxOxycodoneHydrochloride(e) {
      let value = e.detail.value
      let form = {
        morphineInjection: this.calculate(10 / 20 * value),
        sufentanil:  this.calculate(10 / 20 * value),
        morphineTablets: this.calculate(30 / 20 * value),
        morphineSulfate: this.calculate(30 / 20 * value),
        hydromorphone:  this.calculate(10 / 20 / 5 * value),
        Minhydromorphone:  this.calculate(10 / 20 / 8 * value),
        Maxhydromorphone:  this.calculate(10 / 20 / 5 * value),
        MinOxycodoneHydrochloride: this.calculate(15 / 20 * value),
        MaxOxycodoneHydrochloride: value,
        fentanyl: this.calculate(2.1 / 20 * value),
        // breakthroughPain: `${this.calculate(3 / 20 * value)} ~ ${this.calculate(6 / 20 * value)}`
      }

      this.setData({
        form: form
      })
    },

    hydromorphone(e) {
      let value = e.detail.value
      let form = {
        morphineInjection: this.calculate( value * 5 ),
        sufentanil: this.calculate( value * 5 ),
        morphineTablets: this.calculate(value * 3 * 5),
        morphineSulfate: this.calculate(value * 3 * 5 ),
        MinOxycodoneHydrochloride: this.calculate(value * 1.5 * 5),
        MaxOxycodoneHydrochloride: this.calculate(value * 2 * 5),
        hydromorphone: value,
        fentanyl: this.calculate(value * 0.21 * 5),
      }

      this.setData({
        form: form
      })
    },

    Minhydromorphone(e) {
      let value = e.detail.value
      let form = {
        morphineInjection: this.calculate( value * 5 ),
        sufentanil: this.calculate( value * 5 ),
        morphineTablets: this.calculate(value * 3 * 5),
        morphineSulfate: this.calculate(value * 3 * 5 ),
        MinOxycodoneHydrochloride: this.calculate(value * 1.5 * 5),
        MaxOxycodoneHydrochloride: this.calculate(value * 2 * 5),
        Minhydromorphone: value,
        // Maxhydromorphone: this.calculate( 5 / 8  * value ),
        Maxhydromorphone: this.calculate( 8 / 5 * value ),
        fentanyl: this.calculate(value * 0.21 * 5),
      }

      this.setData({
        form: form
      })
    },

    Maxhydromorphone(e) {
      let value = e.detail.value
      let form = {
        morphineInjection: this.calculate( value * 8 ),
        sufentanil: this.calculate( value * 8 ),
        morphineTablets: this.calculate(value * 3 * 8),
        morphineSulfate: this.calculate(value * 3 * 8 ),
        MinOxycodoneHydrochloride: this.calculate(value * 1.5 * 8),
        MaxOxycodoneHydrochloride: this.calculate(value * 2 * 8),
        // Minhydromorphone: this.calculate( 8 / 5 * value ),
        Minhydromorphone: this.calculate( 5 / 8  * value ),
        Maxhydromorphone: value,
        fentanyl: this.calculate(value * 0.21 * 8),
      }

      this.setData({
        form: form
      })
    },

    // 芬太尼贴剂
    fentanyl(e) {
      let value = e.detail.value
      let form = {
        morphineInjection: this.calculate(10 / 2.1 * value),
        sufentanil: this.calculate(10 / 2.1 * value),
        morphineTablets: this.calculate(30 / 2.1 * value),
        morphineSulfate: this.calculate(30 / 2.1 * value),
        MinOxycodoneHydrochloride: this.calculate(15 / 2.1 * value),
        MaxOxycodoneHydrochloride: this.calculate(20 / 2.1 * value),
        hydromorphone: this.calculate(10 / 2.1 / 5  * value),
        Minhydromorphone: this.calculate(10 / 2.1 / 8 * value),
        Maxhydromorphone: this.calculate(10 / 2.1 / 5  * value),
        fentanyl: value,
        // breakthroughPain: `${this.calculate(3 / 2.1 * value)} ~ ${this.calculate(6 / 2.1 * value)}`
      }

      this.setData({
        form: form
      })
    },

    calculate(value) {
      return Math.round(value * 100) / 100
    }
  }
})